package com.lucene.blog.db.service.impl;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.lucene.blog.bean.Blog;
import com.lucene.blog.db.mapper.BlogMapper;
import com.lucene.blog.db.service.BlogService;

@Service("blogService")
public class BlogServiceImpl implements BlogService {

	@Resource
	private BlogMapper blogMapper;
	
	// 获取博客信息，根据日期月份分组查询
	public List<Blog> getBlogData() throws SQLException {
		return blogMapper.getBlogData();
	}
	
	// 分页查询博客
	public List<Blog> getBlogListWithPaging(Map<String, Object> condition) throws SQLException {
		if(condition != null && condition.size() > 0) {
			return blogMapper.getBlogListWithPaging(condition);
		}
		return null;
	}
	
	// 获取总记录数
	public long getBlogCount(Map<String, Object> condition) throws SQLException {
		if(condition != null && condition.size() > 0) {
			return blogMapper.getBlogCount(condition);
		}
		return 0;
	}
	
	// 根据id获取博客
	public Blog findBlogById(Integer blogId) throws SQLException {
		return blogMapper.findBlogById(blogId);
	}
	
	// 获取上一篇博客
	public Blog getPrevBlog(Integer blogId) throws SQLException {
		return blogMapper.getPrevBlog(blogId);
	}
	
	// 获取下一篇博客
	public Blog getNextBlog(Integer blogId) throws SQLException {
		return blogMapper.getNextBlog(blogId);
	}
	
	// 根据博主编号+博客类型的id查询该类型下的博客数量
	public int getBlogCountByTypeId(Integer blogTypeId) throws SQLException {
		return blogMapper.getBlogCountByTypeId(blogTypeId);
	}
	
	// 添加博客
	public int addBlog(Blog blog) throws SQLException {
		if(blog != null) {
			return blogMapper.addBlog(blog);
		}
		return 0;
	}
	
	// 更新博客信息
	public int updateBlog(Blog blog) throws SQLException {
		if(blog != null) {
			return blogMapper.updateBlog(blog);
		}
		return 0;
	}
	
	// 删除博客信息
	public int deleteBlog(Integer blogId) throws SQLException {
		return blogMapper.deleteBlog(blogId);
	}
}
